package logic

import (
	"context"
	"jd-mall/jd/jdclient"

	"jd-mall/api/internal/svc"
	"jd-mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopAddLogic) ShopAdd(req *types.ShopAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.JdRpc.ShopAdd(l.ctx, &jdclient.ShopAddRequest{
		Title:     req.Title,
		Price:     float32(req.Price),
		Num:       req.Num,
		Image:     req.Image,
		Status:    req.Status,
		ConStatus: req.ConStatus,
	})
	if err != nil {
		return &types.Response{
			Code: 200,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "添加成功",
		Data: add,
	}, nil
}
